<?

//Data loading
$title='STATEMENT OF CASH FLOWS (DIRECT)';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. MASAJI PRAYASA CARGO';

$page   = 'PAGE';

$DEFINE_FONT=0;
$pdf=new GridPDFReport("P","mm","Letter");
$fromDate = GetParam("fromDate","");
$toDate  = GetParam("toDate","");
$pdf->AddPage();
//$Result = GridList ();
$pdf->GridTable();
$pdf->Output();


function Neraca ($PYear,$PMonth) {
    global $DBConnection;

    //$TEMP = "TEMPORARY";

    $Year   = $PYear;
    $LastYear = $Year-1;
    $Month  = $PMonth;
    if ($Month=="AUDIT") $Month=13;
    if ($Month<10) $Month = "0".$Month;

    if (($Month-1)<10) $LastMonth = "0".($Month-1);
    else $LastMonth = $Month-1;

    if ($Month<2) $LastMonth = "awal";
    else {$LastMonth = "aku".$LastMonth;}

    $Mutasi = "(mutd".$Month."-"."mutk".$Month.") as mutasi";
    $CurrentMonth = "aku".$Month." as cmonth";

    $SQL = "DROP TABLE IF EXISTS `tblcoatmp`";
    $DBConnection->dbc->query($SQL);

    $SQL = "DROP TABLE IF EXISTS `tblcoatmp_last`";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        CREATE $TEMP TABLE `tblcoatmp` (
        `skada` VARCHAR( 64 ) NOT NULL,
        `pathprn` VARCHAR( 64 ) NOT NULL,
        `namacc` VARCHAR( 64 ) NOT NULL,
        `parent` VARCHAR( 24 ) NOT NULL,
        `printing` tinyint( 4 ) NOT NULL,
        `jumlah` tinyint( 4 ) NOT NULL,
        `grup` tinyint( 4 ) NOT NULL,
        `akumulasi` decimal( 16,4) NOT NULL,
        `lastakumulasi` decimal( 16,4) NOT NULL,
        `lastmonth` decimal( 16,4) NOT NULL,
        `ktrasl` VARCHAR( 4 ) NOT NULL
        );
    ";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        CREATE $TEMP TABLE `tblcoatmp_last` (
        `skada` VARCHAR( 64 ) NOT NULL,
        `akumulasi` decimal( 16,4) NOT NULL,
                `ktrasl` VARCHAR( 4 ) NOT NULL
        );
    ";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        INSERT INTO tblcoatmp_last
        SELECT skada, $CurrentMonth, ktrasl
        FROM tblcoa WHERE tipe=1 AND ledger='$LastYear'
    ";

    if (GetParam("office",""))  $SQL .= "AND tblcoa.ktrasl='".GetParam("office","")."'";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        INSERT INTO tblcoatmp
        SELECT tblcoa.skada, tblcoa.pathprn, tblcoa.namacc, tblcoa.parent, tblcoa.printing, tblcoa.jumlah, tblcoa.grup, $CurrentMonth, tblcoatmp_last.akumulasi, $LastMonth, tblcoa.ktrasl
        FROM tblcoa LEFT JOIN tblcoatmp_last ON tblcoatmp_last.skada=tblcoa.skada AND tblcoatmp_last.ktrasl=tblcoa.ktrasl
        WHERE tipe=1 AND ledger='$Year'
    ";

    if (GetParam("office",""))      $SQL .= "AND tblcoa.ktrasl='".GetParam("office","")."'";
    $DBConnection->dbc->query($SQL);

    $SQL = "DROP TABLE IF EXISTS `tblcoa_totaltmp`";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        CREATE $TEMP TABLE `tblcoa_totaltmp` (
        `skada` VARCHAR( 64 ) NOT NULL,
        `pathprn` VARCHAR( 64 ) NOT NULL,
        `namacc` VARCHAR( 64 ) NOT NULL,
        `parent` VARCHAR( 24 ) NOT NULL,
        `printing` tinyint( 4 ) NOT NULL,
        `jumlah` tinyint( 4 ) NOT NULL,
        `grup` tinyint( 4 ) NOT NULL,
        `mutd` decimal( 16,4) NOT NULL,
        `mutk` decimal( 16,4) NOT NULL,
        `akumulasi` decimal( 16,4) NOT NULL,
        `lastakumulasi` decimal( 16,4) NOT NULL,
        `lastmonth` decimal( 16,4) NOT NULL,
        `ktrasl` VARCHAR( 4 ) NOT NULL
        );
    ";
    $DBConnection->dbc->query($SQL);

    $SQL  = "
        INSERT INTO tblcoa_totaltmp
        SELECT tblcoatmp.skada, tblcoatmp.pathprn, tblcoatmp.namacc, tblcoatmp.parent, tblcoatmp.printing,
                tblcoatmp.jumlah, tblcoatmp.grup, sum(mutd$Month), sum(mutk$Month), sum(aku$Month), lastakumulasi, sum($LastMonth), tblcoa.ktrasl
        FROM tblcoatmp, tblcoa
        WHERE tblcoa.pathprn like concat(tblcoatmp.pathprn,'%') AND tblcoatmp.ktrasl=tblcoa.ktrasl
    ";

    if (GetParam("office","")) $SQL .= " AND tblcoa.ktrasl='".GetParam("office","")."' ";

    $SQL .= "GROUP BY tblcoatmp.skada";
    //print $SQL."<p>\n";die();
    $DBConnection->dbc->query($SQL);
}

function GridList () {
    $DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    list($day,$month,$year) = explode("/",GetParam("fromDate",""));
    $fromDate = date('Y-m-d',mktime(0,0,0,$month,$day,$year));
    list($day,$month,$year) = explode("/",GetParam("toDate",""));
    $toDate   = date('Y-m-d',mktime(0,0,0,$month,$day,$year));

    $wherenobkt = "(nobkt like 'ZTB%')";
    $SQL = "SELECT *, DATE_FORMAT(tglbkt,'%d/%m/%y') as trdate FROM ais_memorial_z WHERE ".$wherenobkt." AND tglbkt>='$fromDate' AND tglbkt<='$toDate' AND urut<>999";
    if (GetParam("office",""))
    $SQL .= " AND ktrasl= '".GetParam("office","")."'";

    if (GetParam("skada",""))
    $SQL .= " AND skada= '".GetParam("skada","")."'";

    $SQL .= " ORDER BY nobkt";
    //print $SQL."<br><br>\n\n\n\n";die();
    $MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
    return $MyResult;
}

function BuildPeriod ($year, $month) {
  $arraymonth = array("","JANUARI","FEBRUARI","MARET","APRIL","MEI","JUNI","JULI","AGUSTUS","SEPTEMBER","OKTOBER","NOPEMBER","DESEMBER");
  return strtoupper(date("d F Y", mktime(0, 0, 0, $month+1, 0, $year)));

}

function BuildMonthYear ($year, $month) {
  $arraymonth = array("","JANUARI","FEBRUARI","MARET","APRIL","MEI","JUNI","JULI","AGUSTUS","SEPTEMBER","OKTOBER","NOPEMBER","DESEMBER");
  return strtoupper(date("F Y", mktime(0, 0, 0, $month+1, 0, $year)));
}

    function GetCashReceivedFromCustomer($Year,$Month) {
        global $DBConnection;
        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))
                FROM ais_memorial WHERE
                (skada like '0004%' OR
                skada like '0005%' OR
                skada like '0006%' OR
                skada like '0007%' OR
                skada like '0008%' OR
                skada like '0009%' OR
                skada like '0010%' OR
                skada like '0012%' OR
                skada like '2001%' OR
                skada like '2004%' OR
                skada like '2005%' OR
                skada like '3001%' OR
                skada like '3002%' OR
                skada like '3003%' OR
                skada like '3005%' OR
                skada like '3008%' OR
                skada like '4003%' OR
                skada like '410%' OR
                skada like '6%' OR
                skada like '7%' OR
                skada like '8%' OR
                skada like '9005%') AND
                nobkt like 'T%' AND
                MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year
               ";
        $CashReceivedFromCustomer = $DBConnection->dbc->get_var($SQL);
        return $CashReceivedFromCustomer*-1;

    }

    function GetPaidToVendor($Year,$Month) {
        global $DBConnection;
        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))
                FROM ais_memorial WHERE
                (skada like '0004%' OR
                skada like '0005%' OR
                skada like '0006%' OR
                skada like '0007%' OR
                skada like '0008%' OR
                skada like '0009%' OR
                skada like '0010%' OR
                skada like '0012%' OR
                skada like '2001%' OR
                skada like '2004%' OR
                skada like '2005%' OR
                skada like '3001%' OR
                skada like '3002%' OR
                skada like '3003%' OR
                skada like '3005%' OR
                skada like '3008%' OR
                skada like '4003%' OR
                skada like '410%' OR
                skada like '6%' OR
                skada like '7%' OR
                skada like '8%' OR
                skada like '9005%') AND
                NOT (skada like '001004%') AND
                NOT (skada like '001005%') AND
                nobkt like 'B%' AND
                MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year
               ";
        $PaidToVendor = $DBConnection->dbc->get_var($SQL);
        return $PaidToVendor*-1;

    }

    function GetInterestExpenses($Year,$Month) {
        global $DBConnection;
        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE skada like '9002%' AND nobkt like 'B%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $InterestExpense = $DBConnection->dbc->get_var($SQL);
        return $InterestExpense*-1;
    }

    function GetTaxExpenses($Year,$Month) {
        global $DBConnection;
        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE (skada like '3004%' OR skada like '001004%' OR skada like '001005%') AND nobkt like 'B%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $Expense = $DBConnection->dbc->get_var($SQL);

        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE (skada like '3004%' OR skada like '001004%' OR skada like '001005%') AND nobkt like 'T%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $Expense2 = $DBConnection->dbc->get_var($SQL);

        $TaxExpenses = $Expense+$Expense2;


        return $TaxExpenses*-1;
    }

    function ReceivedFromInterest($Year,$Month) {
        global $DBConnection;
        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE skada like '9001%' AND nobkt like 'T%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $ReceivedFromInterest = $DBConnection->dbc->get_var($SQL);

        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE skada like '9001%' AND nobkt like 'B%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $ReceivedFromInterest2 = $DBConnection->dbc->get_var($SQL);

        return ($ReceivedFromInterest+$ReceivedFromInterest2)*-1;
    }


    function GetPurchasedFixedAsset($Year,$Month) {
        global $DBConnection;

        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))  FROM ais_memorial WHERE (skada like '1001%' OR skada like '1003%') AND (nobkt like 'B%') AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $B_PurchasedFixedAsset = $DBConnection->dbc->get_var($SQL);

        $PurchasedFixedAsset = $B_PurchasedFixedAsset;
        return $PurchasedFixedAsset*-1;
    }

    function GetSalesFixedAsset($Year,$Month) {
        global $DBConnection;
        $SQL = "SELECT SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE skada like '9003%' AND (nobkt like 'T%') AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $Current_SalesFixedAsset = $DBConnection->dbc->get_var($SQL);
        $Current_SalesFixedAsset = $Current_SalesFixedAsset==""?0:$Current_SalesFixedAsset;
        $SalesFixedAsset = $Current_SalesFixedAsset;

        return $SalesFixedAsset;
    }

    function GetDefferedExpense($Year,$Month) {
        global $DBConnection;

        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE skada like '20030%' AND (nobkt like 'B%' OR nobkt like 'T%') AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $Current_DefferedExpense = $DBConnection->dbc->get_var($SQL);
        $Current_DefferedExpense = $Current_DefferedExpense==""?0:$Current_DefferedExpense;

        $DefferedExpense = $Current_DefferedExpense;

        return $DefferedExpense*-1;
    }

    function GetPaidInCapital($Year,$Month) {
        global $DBConnection;

        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE skada like '500%' AND nobkt like 'T%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $Current_PaidInCapital = $DBConnection->dbc->get_var($SQL);
        $Current_PaidInCapital = $Current_PaidInCapital==""?0:$Current_PaidInCapital;

        $PaidInCapital = $Current_PaidInCapital;

        return $PaidInCapital;
    }

    function GetPaymentDividen($Year,$Month) {
        global $DBConnection;

        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE skada like '9006%' AND nobkt like 'B%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $Current_PaymentDividen = $DBConnection->dbc->get_var($SQL);
        $Current_PaymentDividen = $Current_PaymentDividen==""?0:$Current_PaymentDividen;
        $PaymentDividen = $Current_PaymentDividen;

        return $PaymentDividen;
    }

    function GetReceivedLoan($Year,$Month) {
        global $DBConnection;

        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE (skada like '3006%' OR skada like '3007%' OR skada like '4001%' OR skada like '4003%') AND nobkt like 'T%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $Current_ReceivedLoan = $DBConnection->dbc->get_var($SQL);
        $Current_ReceivedLoan = $Current_ReceivedLoan==""?0:$Current_ReceivedLoan;

        $ReceivedLoan = $Current_ReceivedLoan;

        return $ReceivedLoan*-1;
    }

    function GetPaymentLoan($Year,$Month) {
        global $DBConnection;

        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE (skada like '3006%' OR skada like '3007%' OR skada like '4001%' OR skada like '4003%') AND nobkt like 'B%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $Current_PaymentLoan = $DBConnection->dbc->get_var($SQL);
        $Current_PaymentLoan = $Current_PaymentLoan==""?0:$Current_PaymentLoan;

        $PaymentLoan = $Current_PaymentLoan*-1;

        return $PaymentLoan;
    }


    function GetBeginingOfPeriod($Year,$Month) {
        global $DBConnection;
        Neraca($Year,$Month);
        if ($Month>1) {
            Neraca($Year,$Month-1);
            $SQL = "SELECT SUM(akumulasi) FROM tblcoa_totaltmp WHERE (skada='0001' OR skada='0002' OR skada='0003' OR skada='0005')";
        }else {

            $SQL = "SELECT SUM(lastmonth) FROM tblcoa_totaltmp WHERE (skada='0001' OR skada='0002' OR skada='0003' OR skada='0005')";
        }
        $Last_BeginingOfPeriod = $DBConnection->dbc->get_var($SQL);

        //print $Last_BeginingOfPeriod;
        $Last_BeginingOfPeriod = $Last_BeginingOfPeriod==""?0:$Last_BeginingOfPeriod;



        return $Last_BeginingOfPeriod;
    }

    function GetForexAdjustment($Year,$Month) {
        global $DBConnection;
        $SQL = "SELECT SUM(IF(dk='D',rupiah,0))-SUM(IF(dk='K',rupiah,0))  FROM ais_memorial WHERE (skada like '0001%' OR skada like '0002%' OR skada like '0003%') AND nobkt like 'M%' AND MONTH(tglbkt)=$Month AND YEAR(tglbkt)=$Year";
        $ForexAdjustment = $DBConnection->dbc->get_var($SQL);
        $ForexAdjustment = $ForexAdjustment==""?0:$ForexAdjustment;

        return $ForexAdjustment;
    }

    function GetNeraca($Year,$Month) {
        $Year = date("Y", mktime(0, 0, 0, $Month, 1, $Year));
        $Month = date("n", mktime(0, 0, 0, $Month, 1, $Year));
        //Neraca($Year,$Month);
        $result["CASH_FROM_CUST"]   = GetCashReceivedFromCustomer($Year,$Month);
        $result["INTEREST_EXPENSE"] = GetInterestExpenses($Year,$Month);
        $result["PAID_TO"] = GetPaidToVendor($Year,$Month);
        $result["CASH_FROM_OE"] = $result["CASH_FROM_CUST"]+$result["PAID_TO"];
        $result["TAX_EXPENSES"] = GetTaxExpenses($Year,$Month);
        $result["RECEIVED_INTEREST_REVENUE"] = ReceivedFromInterest($Year,$Month);
        $result["NET_FROM_OA"] = $result["CASH_FROM_OE"]+$result["TAX_EXPENSES"]+$result["RECEIVED_INTEREST_REVENUE"]+$result["INTEREST_EXPENSE"];
        $result["PURCHASED_FIXED_ASSET"] = GetPurchasedFixedAsset($Year,$Month);
        $result["SALES_FIXED_ASSET"] = GetSalesFixedAsset($Year,$Month);
        $result["INC_DEC_DEFFERED"] = GetDefferedExpense($Year,$Month);
        $result["NET_FROM_IA"] = $result["PURCHASED_FIXED_ASSET"]+$result["SALES_FIXED_ASSET"]+$result["INC_DEC_DEFFERED"];
        $result["PAID_IN_CAPITAL"] = GetPaidInCapital($Year,$Month);
        $result["PAYMENT_DIVIDEN"] = GetPaymentDividen($Year,$Month);
        $result["RECEIVED_FROM_LOAN"] = GetReceivedLoan($Year,$Month);
        $result["PAYMENT_LONG_TERM"] = GetPaymentLoan($Year,$Month);
        $result["NET_FROM_FA"] = $result["PAID_IN_CAPITAL"]+$result["PAYMENT_DIVIDEN"]+$result["RECEIVED_FROM_LOAN"]+$result["PAYMENT_LONG_TERM"];
        $result["INC_DEC_PERIOD"] = $result["NET_FROM_OA"]+$result["NET_FROM_IA"]+$result["NET_FROM_FA"];
        $result["BEGINING_PERIOD"] = GetBeginingOfPeriod($Year,$Month) ;
        $result["ADJUSTMENT_FOREX"] = GetForexAdjustment($Year,$Month);
        $result["END_PERIOD"] = $result["INC_DEC_PERIOD"]+ $result["BEGINING_PERIOD"]+$result["ADJUSTMENT_FOREX"];
        return $result;
    }

class GridPDFReport extends PDF {
    function Header() {
        global $title,$perush,$page,$DEFINE_FONT;
        if ($DEFINE_FONT==0) {
            $this->AddFont('arialn','','arialn.php');
            $DEFINE_FONT=1;
        }
        //$this->SetLeftMargin(5);
        $Month = GetParam("m","");
        $Year  = GetParam("y","");
        $this->SetFont('arialn','',10);
        $this->Cell(200,5,$perush,0,1,'C',0);
        $this->Cell(200,5,$title,0,1,'C',0);
        $this->Cell(200,5,"PERIOD: ".BuildPeriod ($Year,$Month),0,1,'C',0);
        $this->SetLeftMargin(5);
        $this->Cell(200,5,$page." ".$this->PageNo(),0,1,'R',0);
        $this->Line(5,30,210,30);
        $this->Ln();
        $this->Ln();
        //Header
        //Column widths
        $w=array(100,30,30,30);
        //$this->SetFont('arialn','',10);

        $this->Cell($w[0],7,"DESCRIPTION",1,0,'C',0);
        $this->Cell($w[1],7,BuildMonthYear ($Year-2, $Month),1,0,'C',0);
        $this->Cell($w[2],7,BuildMonthYear ($Year-1, $Month),1,0,'C',0);
        $this->Cell($w[3],7,BuildMonthYear ($Year, $Month),1,0,'C',0);
        $this->Ln();

        $this->SetFont('arialn','',8);
    }


    function GridTable() {
        //Column widths
        $Year = GetParam("y","");
        $Month = GetParam("m","");

        $Current = GetNeraca($Year,$Month);
        $Curren1 = GetNeraca($Year-1,$Month);
        $Curren2  = GetNeraca($Year-2,$Month);

        $w=array(100,30,30,30);
        $this->Cell($w[0],5,"","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'C',0);
        $this->Cell($w[2],5,"","LR",0,'R',0);
        $this->Cell($w[3],5,"","LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"CASH FLOWS FROM OPERATING ACTIVITIES :","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'L',0);
        $this->Cell($w[2],5,"","LR",0,'L',0);
        $this->Cell($w[3],5,"","LR",0,'L',0);
        $this->Ln();
        $this->Cell($w[0],5,"   CASH RECEIVED FROM CUSTOMER","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["CASH_FROM_CUST"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["CASH_FROM_CUST"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["CASH_FROM_CUST"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   CASH PAID TO VENDOR, EMPLOYEE & OTHER OPERATING EXPENSES","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["PAID_TO"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["PAID_TO"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["PAID_TO"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   CASH FROM OPERATING ACTIVITIES","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["CASH_FROM_OE"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["CASH_FROM_OE"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["CASH_FROM_OE"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   PAID FOR :","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'R',0);
        $this->Cell($w[2],5,"","LR",0,'R',0);
        $this->Cell($w[3],5,"","LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"     INTEREST EXPENSES","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["INTEREST_EXPENSE"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["INTEREST_EXPENSE"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["INTEREST_EXPENSE"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"     TAX EXPENSES","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["TAX_EXPENSES"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["TAX_EXPENSES"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["TAX_EXPENSES"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   RECEIVED FROM INTEREST REVENUE","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["RECEIVED_INTEREST_REVENUE"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["RECEIVED_INTEREST_REVENUE"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["RECEIVED_INTEREST_REVENUE"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'C',0);
        $this->Cell($w[2],5,"","LR",0,'R',0);
        $this->Cell($w[3],5,"","LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],7,"NET CASH FLOWS FROM (USED IN) OPERATING ACTIVITIES",1,0,'R',0);
        $this->Cell($w[1],7,FormatNumber($Curren2["NET_FROM_OA"]),1,0,'R',0);
        $this->Cell($w[2],7,FormatNumber($Curren1["NET_FROM_OA"]),1,0,'R',0);
        $this->Cell($w[3],7,FormatNumber($Current["NET_FROM_OA"]),1,0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"CASH FLOWS FROM INVESTING ACTIVITIES :","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'R',0);
        $this->Cell($w[2],5,"","LR",0,'R',0);
        $this->Cell($w[3],5,"","LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   PURCHASE OF FIXED ASSETS","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["PURCHASED_FIXED_ASSET"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["PURCHASED_FIXED_ASSET"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["PURCHASED_FIXED_ASSET"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   SALES OF FIXED ASSETS","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["SALES_FIXED_ASSET"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["SALES_FIXED_ASSET"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["SALES_FIXED_ASSET"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   INCREASE (DECREASE) DEFFERED EXPENSES","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["INC_DEC_DEFFERED"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["INC_DEC_DEFFERED"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["INC_DEC_DEFFERED"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'C',0);
        $this->Cell($w[2],5,"","LR",0,'R',0);
        $this->Cell($w[3],5,"","LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],7,"NET CASH FLOWS FROM (USED IN) INVESTING ACTIVITIES",1,0,'R',0);
        $this->Cell($w[1],7,FormatNumber($Curren2["NET_FROM_IA"]),1,0,'R',0);
        $this->Cell($w[2],7,FormatNumber($Curren1["NET_FROM_IA"]),1,0,'R',0);
        $this->Cell($w[3],7,FormatNumber($Current["NET_FROM_IA"]),1,0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"CASH FLOWS FROM FINANCING ACTIVITIES :","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'L',0);
        $this->Cell($w[2],5,"","LR",0,'R',0);
        $this->Cell($w[3],5,"","LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   ADDITIONAL PAID IN CAPITAL","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["PAID_IN_CAPITAL"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["PAID_IN_CAPITAL"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["PAID_IN_CAPITAL"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   PAYMENTS OF DIVIDENDS","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["PAYMENT_DIVIDEN"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["PAYMENT_DIVIDEN"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["PAYMENT_DIVIDEN"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   RECEIVED FROM LOAN","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["RECEIVED_FROM_LOAN"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["RECEIVED_FROM_LOAN"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["RECEIVED_FROM_LOAN"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"   REPAYMENT OF LONG TERM DEBTS","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["PAYMENT_LONG_TERM"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["PAYMENT_LONG_TERM"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["PAYMENT_LONG_TERM"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'L',0);
        $this->Cell($w[2],5,"","LR",0,'L',0);
        $this->Cell($w[3],5,"","LR",0,'L',0);
        $this->Ln();
        $this->Cell($w[0],7,"     NET CASH FLOWS FROM FINANCING ACTIVITIES",1,0,'R',0);
        $this->Cell($w[1],7,FormatNumber($Curren2["NET_FROM_FA"]),1,0,'R',0);
        $this->Cell($w[2],7,FormatNumber($Curren1["NET_FROM_FA"]),1,0,'R',0);
        $this->Cell($w[3],7,FormatNumber($Current["NET_FROM_FA"]),1,0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'L',0);
        $this->Cell($w[2],5,"","LR",0,'L',0);
        $this->Cell($w[3],5,"","LR",0,'L',0);
        $this->Ln();
        $this->Cell($w[0],5,"FOREX ADJUSTMENT","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["ADJUSTMENT_FOREX"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["ADJUSTMENT_FOREX"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["ADJUSTMENT_FOREX"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"CASH AND CASH EQUIVALENTS :","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'L',0);
        $this->Cell($w[2],5,"","LR",0,'R',0);
        $this->Cell($w[3],5,"","LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"  INCREASE (DECREASE) DURING THE PERIOD","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["INC_DEC_PERIOD"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["INC_DEC_PERIOD"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["INC_DEC_PERIOD"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],5,"  BEGINNING OF THE PERIOD","LR",0,'L',0);
        $this->Cell($w[1],5,FormatNumber($Curren2["BEGINING_PERIOD"]),"LR",0,'R',0);
        $this->Cell($w[2],5,FormatNumber($Curren1["BEGINING_PERIOD"]),"LR",0,'R',0);
        $this->Cell($w[3],5,FormatNumber($Current["BEGINING_PERIOD"]),"LR",0,'R',0);
        $this->Ln();
        $this->Cell($w[0],7,"  ENDING OF THE PERIOD",1,0,'R',0);
        $this->Cell($w[1],7,FormatNumber($Curren2["END_PERIOD"]),1,0,'R',0);
        $this->Cell($w[2],7,FormatNumber($Curren1["END_PERIOD"]),1,0,'R',0);
        $this->Cell($w[3],7,FormatNumber($Current["END_PERIOD"]),1,0,'R',0);
        $this->Ln();

        /*
        $this->Cell($w[0],5,"","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'L',0);
        $this->Cell($w[2],5,"","LR",0,'L',0);
        $this->Cell($w[3],5,"","LR",0,'L',0);
        $this->Ln();
        $this->Cell($w[0],5,"","LR",0,'L',0);
        $this->Cell($w[1],5,"","LR",0,'L',0);
        $this->Cell($w[2],5,"","LR",0,'L',0);
        $this->Cell($w[3],5,"","LR",0,'L',0);
        $this->Ln();
*/
        //Data
    }

    function Footer() {
        //Closure line
        //$this->Cell(200,0,'','T');
    }

}


?>
